// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: Definition of event string arrays.
//   $Id$


#include "stdafx.h"
#include "XForms.h"
#include "XFormsApp.h"

#include "XFormsElement.h"
#include "FormControlInputUI.h"
#include "SingleNodeBindingUI.h"
#include "NodesetBindingUI.h"
#include "ButtonUI.h"
#include "InputUI.h"
#include "OutputUI.h"
#include "RepeatUI.h"
#include "RangeUI.h"
#include "SecretUI.h"
#include "SubmitUI.h"
#include "SubmissionUI.h"
#include "SwitchUI.h"
#include "TextAreaUI.h"
#include "ModelUI.h"
#include "XFormsElementMessage.h"


//UIEventFirer macro, calls the FireEvent function 
//	with the appropriate variables.
#define UIEventFirer(className,evName,evPosition) \
	HRESULT className::on##evName(){return FireEvent(m_alEventCookies[evPosition],0);}


//TODO: change this to array of wides.
//		Currently, the event name constants
//		are char strings.
const CComBSTR * const CXFormsElement::sm_asEventNames[] 
= 
{
	&EVENT_HELP,
	&EVENT_HINT,
	&EVENT_ACTIVATE,
	&EVENT_INRANGE,
	&EVENT_OUTOFRANGE,
	&EVENT_DOMFOCUS_IN,
	&EVENT_DOMFOCUS_OUT,
	&EVENT_VALID,
	&EVENT_INVALID,
	&EVENT_READWRITE,
	&EVENT_READONLY,
	&EVENT_REQUIRED,
	&EVENT_OPTIONAL,
	&EVENT_DISABLED,
	&EVENT_ENABLED,
	&EVENT_VALUECHANGED,
	&EVENT_PREVIOUS,
	&EVENT_NEXT,
	&EVENT_VALUECHANGING
};

#define EVENT_ARRAYPOSITION_HELP 0
#define EVENT_ARRAYPOSITION_HINT 1
#define EVENT_ARRAYPOSITION_DOMACTIVATE 2
#define EVENT_ARRAYPOSITION_INRANGE 3 
#define EVENT_ARRAYPOSITION_OUTOFRANGE 4
#define EVENT_ARRAYPOSITION_DOMFOCUSIN 5
#define EVENT_ARRAYPOSITION_DOMFOCUSOUT 6
#define EVENT_ARRAYPOSITION_VALID 7
#define EVENT_ARRAYPOSITION_INVALID 8		
#define EVENT_ARRAYPOSITION_READWRITE 9
#define EVENT_ARRAYPOSITION_READONLY 10 
#define EVENT_ARRAYPOSITION_REQUIRED 11
#define EVENT_ARRAYPOSITION_OPTIONAL 12
#define EVENT_ARRAYPOSITION_DISABLED 13
#define EVENT_ARRAYPOSITION_ENABLED 14
#define EVENT_ARRAYPOSITION_VALUECHANGED 15
#define EVENT_ARRAYPOSITION_PREVIOUS 16
#define EVENT_ARRAYPOSITION_NEXT 17
#define EVENT_ARRAYPOSITION_VALUECHANGING 18


//Events fired by node bindings.

/*
	HRESULT CXFormsElement::onvalid()
	{
		valid(true);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_VALID],0);
	}

	HRESULT CXFormsElement::oninvalid()
	{
		valid(false);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_INVALID],0);
	}
	
	HRESULT CXFormsElement::onreadwrite()
	{
		readonly(false);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_READWRITE],0);
	}

	HRESULT CXFormsElement::onreadonly()
	{
		readonly(true);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_READONLY],0);
	}

	HRESULT CXFormsElement::onrequired()
	{
		required(true);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_REQUIRED],0);
	}

	HRESULT CXFormsElement::onoptional()
	{
		required(false);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_OPTIONAL],0);
	}

	HRESULT CXFormsElement::ondisabled()
	{
		enable(false);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_DISABLED],0);
	}

	HRESULT CXFormsElement::onenabled()
	{
		enable(true);
		return FireEvent(m_alEventCookies[EVENT_ARRAYPOSITION_ENABLED],0);
	}
	
	UIEventFirer(CXFormsElement,valuechanged,EVENT_ARRAYPOSITION_VALUECHANGED)
	UIEventFirer(CXFormsElement,valuechanging,EVENT_ARRAYPOSITION_VALUECHANGING)
	//Events fired by UI interaction.
	UIEventFirer(CXFormsElement,next,EVENT_ARRAYPOSITION_NEXT)
	UIEventFirer(CXFormsElement,previous,EVENT_ARRAYPOSITION_PREVIOUS)
	UIEventFirer(CXFormsElement,DOMFocusIn,EVENT_ARRAYPOSITION_DOMFOCUSIN)
	UIEventFirer(CXFormsElement,DOMFocusOut,EVENT_ARRAYPOSITION_DOMFOCUSOUT)
	UIEventFirer(CXFormsElement,InRange,EVENT_ARRAYPOSITION_INRANGE)
	UIEventFirer(CXFormsElement,OutOfRange,EVENT_ARRAYPOSITION_OUTOFRANGE)
	UIEventFirer(CXFormsElement,DOMActivate,EVENT_ARRAYPOSITION_DOMACTIVATE)
	UIEventFirer(CXFormsElement,hint,EVENT_ARRAYPOSITION_HINT)
	UIEventFirer(CXFormsElement,help,EVENT_ARRAYPOSITION_HELP)

*/
//=====================================================================
//				CXFormsElementModel
//=====================================================================

const CComBSTR * const CXFormsElementModel::sm_asEventNames[] 
= 
{
	//Construction events
	&EVENT_MODELCONSTRUCT,
	&EVENT_MODELCONSTRUCTDONE,
	&EVENT_READY,
	&EVENT_MODELDESTRUCT,
	
	//Re... events
	&EVENT_REVALIDATE,
	&EVENT_RECALCULATE,
	&EVENT_REBUILD,
	&EVENT_REFRESH,
	&EVENT_RESET,

	//errors
	&EVENT_BINDINGEXCEPT,
	&EVENT_LINKEXCEPT,
	&EVENT_LINKERROR,
	&EVENT_COMPUTEEXCEPT,

	//The following events should be on different
	//	 classes, but those classes don't exist (yet).

	//on instances
	&EVENT_INSERT,
	&EVENT_DELETE,

};

	
#define EVENT_ARRAYPOSITION_MODELCONSTRUCT 0
#define EVENT_ARRAYPOSITION_MODELCONSTRUCTDONE 1
#define EVENT_ARRAYPOSITION_READY 2
#define EVENT_ARRAYPOSITION_MODELDESTRUCT 3

#define EVENT_ARRAYPOSITION_REVALIDATE 4
#define EVENT_ARRAYPOSITION_RECALCULATE 5
#define EVENT_ARRAYPOSITION_REBUILD 6
#define EVENT_ARRAYPOSITION_REFRESH 7
#define EVENT_ARRAYPOSITION_RESET 8		

#define EVENT_ARRAYPOSITION_BINDINGEXCEPT 9
#define EVENT_ARRAYPOSITION_LINKEXCEPT 10 
#define EVENT_ARRAYPOSITION_LINKERROR 11
#define EVENT_ARRAYPOSITION_COMPUTEEXCEPT 12

#define EVENT_ARRAYPOSITION_INSERT 13
#define EVENT_ARRAYPOSITION_DELETE 14
/*
//Construction/destruction events.
UIEventFirer(CXFormsElementModel,ModelConstruct,EVENT_ARRAYPOSITION_MODELCONSTRUCT)
UIEventFirer(CXFormsElementModel,ModelConstructDone,EVENT_ARRAYPOSITION_MODELCONSTRUCTDONE)
UIEventFirer(CXFormsElementModel,Ready,EVENT_ARRAYPOSITION_READY)
UIEventFirer(CXFormsElementModel,ModelDestruct,EVENT_ARRAYPOSITION_MODELDESTRUCT)

//errors
UIEventFirer(CXFormsElementModel,BindingException, EVENT_ARRAYPOSITION_BINDINGEXCEPT)
UIEventFirer(CXFormsElementModel,LinkError,EVENT_ARRAYPOSITION_LINKERROR)
UIEventFirer(CXFormsElementModel,LinkException,EVENT_ARRAYPOSITION_LINKEXCEPT)
UIEventFirer(CXFormsElementModel,ComputeException,EVENT_ARRAYPOSITION_COMPUTEEXCEPT)

//These are actually targeted at instance
//	but instance does not have a viewlink.
UIEventFirer(CXFormsElementModel,Insert,EVENT_ARRAYPOSITION_INSERT)
UIEventFirer(CXFormsElementModel,Delete,EVENT_ARRAYPOSITION_DELETE)

//re... events

UIEventFirer(CXFormsElementModel,Rebuild,EVENT_ARRAYPOSITION_REBUILD)
UIEventFirer(CXFormsElementModel,Recalculate,EVENT_ARRAYPOSITION_RECALCULATE)
UIEventFirer(CXFormsElementModel,Revalidate,EVENT_ARRAYPOSITION_REVALIDATE)
UIEventFirer(CXFormsElementModel,Refresh,EVENT_ARRAYPOSITION_REFRESH)
UIEventFirer(CXFormsElementModel,Reset,EVENT_ARRAYPOSITION_RESET)
*/
//=====================================================================
//				CXFormsElementRepeat
//=====================================================================
#define EVENT_ARRAYPOSITION_SCROLLFIRST 0
#define EVENT_ARRAYPOSITION_SCROLLLAST 1


const CComBSTR * const CXFormsElementRepeat::sm_asEventNames[] 
= 
{
	&EVENT_SCROLLFIRST,
	&EVENT_SCROLLLAST
};
/*	//IUIRepeatEvents
	UIEventFirer(CXFormsElementRepeat,ScrollFirst,EVENT_ARRAYPOSITION_SCROLLFIRST)
	UIEventFirer(CXFormsElementRepeat,ScrollLast,EVENT_ARRAYPOSITION_SCROLLLAST)
*/
//=====================================================================
//				CXFormsElementSubmission
//=====================================================================

const CComBSTR *  const CXFormsElementSubmission::sm_asEventNames[] 
= 
{
	&EVENT_SUBMIT,
	&EVENT_SUBMIT_DONE,
	&EVENT_SUBMIT_ERROR
};

#define EVENT_ARRAYPOSITION_SUBMIT 0
#define EVENT_ARRAYPOSITION_SUBMITDONE 1
#define EVENT_ARRAYPOSITION_SUBMITERROR 2
/*
UIEventFirer(CXFormsElementSubmission,Submit,EVENT_ARRAYPOSITION_SUBMIT)
UIEventFirer(CXFormsElementSubmission,SubmitDone,EVENT_ARRAYPOSITION_SUBMITDONE)


*/
//=====================================================================
//				CXFormsElementMessage
//=====================================================================

const CComBSTR *  const CXFormsElementMessage::sm_asEventNames[] 
= 
{
	&EVENT_MESSAGE_SHOW,
	&EVENT_MESSAGE_HIDE,
};

#define EVENT_ARRAYPOSITION_MESSAGE_SHOW 0
#define EVENT_ARRAYPOSITION_MESSAGE_HIDE 1
/*
UIEventFirer(CXFormsElementMessage,Show,EVENT_ARRAYPOSITION_MESSAGE_SHOW)
UIEventFirer(CXFormsElementMessage,Hide,EVENT_ARRAYPOSITION_MESSAGE_HIDE)
*/